package com.eagle.platform.api.controller;

import com.eagle.common.entity.po.AdminUser;
import com.eagle.common.entity.po.query.AdminUserQuery;
import com.eagle.common.entity.vo.PaginationResult;
import com.eagle.common.service.AdminUserService;
import com.eagle.common.util.JacksonUtils;
import com.eagle.platform.api.service.AdminUserBizService;
import com.eagle.platform.api.vo.APIResultVO;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/api/user")
public class AdminUserController extends BaseController{

    private static final Logger LOGGER = LoggerFactory.getLogger(AdminUserController.class);

    @Autowired
    private AdminUserService adminUserService;

    /**
     * 分页获取用户信息
     *
     * @param paramJson 查询条件JSON格式字符串 (参数都以json格式放入request body中传入后台)
     * @return
     */
    @RequestMapping(value = "/list", produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String getUserList(@RequestBody(required = false) String paramJson) {
        AdminUserQuery query = null;
        if (StringUtils.isNotBlank(paramJson)){
            try {
                query = JacksonUtils.fromJson(paramJson, AdminUserQuery.class);
            }catch (Exception e){
                LOGGER.error("参数转换错误,{}",paramJson);
                e.printStackTrace();
            }
        }
        if (query == null){
            query = new AdminUserQuery();
        }
        PaginationResult<AdminUser> page =  this.adminUserService.findListByPage(query);
        return JacksonUtils.toJson(buildSuccessResult(page));
    }
}
